<?php


namespace App\Http\Controllers\Api;


use App\Models\Vip;
use App\Services\PayService;
use App\Services\RefundService;
use Illuminate\Http\Request;

class VipController extends Controller
{
    protected $payService;

    public function __construct()
    {
        $this->payService = app(PayService::class);
    }

    public function list()
    {
        $list = Vip::orderBy('day')->get()->map(function ($item) {
            $item->price = $item->price ? bcmul($item->price, 0.01, 2) : 0;
            return $item;
        });

        return $this->_success([
            'list' => $list
        ]);
    }

    public function unifiedOrder(Request $request, int $vId)
    {
        $memberId = auth('api')->user()->id;

        return $this->_success($this->payService->unifiedOrder($memberId, $this->getMiniType(), $vId));
    }

    public function paidNotify(Request $request, string $sn)
    {
        return $this->payService->paidNotify($sn);
    }

    public function refundNotify(Request $request, string $sn)
    {
        return app(RefundService::class)->refundNotify($sn);
    }
}
